package main.chapter6.sequence

fun main() {
    for (i in fibonacci) {
        println(i)
        if (i > 100) break
    }
}

val fibonacci = sequence {
    yield(1L) // 第一个斐波那数
    var cur = 1L
    var next = 1L

    while (true) {
        yield(next) // 下一个斐波那数
        val tmp = cur + next
        cur = next
        next = tmp
    }
}